package a1_3;

import java.util.ArrayList;
import java.util.List;

/**
 * 指导教师类，关联系部和课程
 */
public class Instructor {
    private String instructorId;
    private String instructorName;

    // 关联：至少属于1个系部（多重性1..* → 此处用单个系部，符合"至少1个"）
    private Department department;

    // 关联：教授1~3门课程（用List存储，控制数量）
    private List<Subject> taughtSubjects = new ArrayList<>();

    public Instructor() {}

    public Instructor(String instructorId, String instructorName, Department department) {
        this.instructorId = instructorId;
        this.instructorName = instructorName;
        this.department = department; // 强制关联系部，满足"至少属于1个"
    }

    // 添加课程（控制1~3门）
    public boolean addTaughtSubject(Subject subject) {
        if (taughtSubjects.size() < 3) {
            return taughtSubjects.add(subject);
        }
        throw new IllegalStateException("教师最多教授3门课程");
    }

    // 移除课程（至少保留1门）
    public boolean removeTaughtSubject(Subject subject) {
        if (taughtSubjects.size() > 1) {
            return taughtSubjects.remove(subject);
        }
        throw new IllegalStateException("教师至少教授1门课程");
    }

    // Getter/Setter
    public String getInstructorId() {
        return instructorId;
    }

    public void setInstructorId(String instructorId) {
        this.instructorId = instructorId;
    }

    public String getInstructorName() {
        return instructorName;
    }

    public void setInstructorName(String instructorName) {
        this.instructorName = instructorName;
    }

    public Department getDepartment() {
        return department;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }

    public List<Subject> getTaughtSubjects() {
        return new ArrayList<>(taughtSubjects);
    }
}
